<!-- $Id: group_buy_info.htm 14216 2015-02-10 02:27:21Z derek $ -->
{include file="pageheader.htm"} {insert_scripts files="../js/utils.js, ../js/validate/jquery.validate.js, ../js/validate/messages_zh.js"}
<script type="text/javascript" src="../js/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="../js/calendar.php?lang={$cfg_lang}"></script>
<link href="../js/calendar/calendar.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="./js/validate/jquery.validate.js"></script>
<script type="text/javascript" src="./js/validate/messages_zh.js"></script>
<script type="text/javascript" src="./js/validator.js"></script>
<style type="text/css">
label.error {
	color: red;
	background: url(./images/warning_small.gif) no-repeat;
	padding-left: 18px;
}

label.success {
	background: url(./images/yes.gif) no-repeat;
	padding-left: 18px;
}
</style>
<div class="form-div">
	<form action="javascript:searchUsers()" name="searchForm" action="" method="post"  enctype="multipart/form-data">
		<!-- 入驻商编号 -->
		<input type="hidden" name="supp_id" value="-1" />
		<img src="images/icon_search.gif" width="26" height="22" border="0" alt="SEARCH" />
		{$lang.label_user_id}
		<!-- 关键字 -->
		<input type="text" name="keyword" size="20" />
		<input type="submit" value="{$lang.button_search}" class="button" />
	</form>
</div>
<!--  onsubmit="return validate()" -->
<form id="form1" method="post" action="dkpt.php?act=insert_update&XDEBUG_SESSION_START=ECLIPSE_DBGP" name="theForm" enctype="multipart/form-data">
	<input type="hidden" id="id" name="id" value="{$dkpt.id}">
	<div class="main-div">
		<table id="group-table" cellspacing="1" cellpadding="3" width="100%">
			
			<tr>
				<td class="label">
					标题
				</td>
				<td>
					<input type="text" id="pt_title" name="pt_title" size="22" value="{$dkpt.pt_title}" class="required" />
					<br />
					<span class="notice-span" {if $help_open}style="display: block" {else} style="display:none" {/if} id="noticOfUsername">{$lang.notice_pt_title}</span>
				</td>
			</tr>
			<tr>
				<td class="label">
					LOGO
				</td>
				<td><input type="file" name="pt_img" size="35">
				<br />
				<input type="text" size="40"  style="color:#aaa;" onfocus="if (this.value == '外部url'){this.value='http://';this.style.color='#000';}" name="pt_img_url" value="{$dkpt.pt_img}" />
				<br />{if $dkpt.is_logo_url eq 1}
						<img src="{$dkpt.pt_img}" alt="">
						{else}
						<img src="../{$dkpt.pt_img}" alt="">
					{/if}
					
				</td>
			</tr>
			<tr>
				<td class="label">
					描述
				</td>
				<td>
					<textarea name="pt_desc" cols="40" rows="3" class="required">{$dkpt.pt_desc}</textarea>
					<br />
					
				</td>
			</tr>
			<tr>
				<td class="label">
				链接
				</td>
				<td>
					<input type="text" id="pt_url" name="pt_url" size="30" value="{$dkpt.pt_url}" placeholder="加上http://" class="required" />
				</td>
			</tr>
			
			<tr>
				<td class="label">&nbsp;</td>
				<td>
					<input name="act_id" type="hidden" id="act_id" value="{$dkpt.act_id}">
					<input type="submit" id="btn_submit" name="btn_submit" value="{$lang.button_submit}" class="button" />
					<input type="reset" value="{$lang.button_reset}" class="button" />
					{if $dkpt.status eq 1}
					<input type="submit" name="finish" value="{$lang.button_finish}" class="button" onclick="return confirm('{$lang.notice_finish}')" />
					{elseif $dkpt.status eq 2}
					<input type="submit" name="succeed" value="{$lang.button_succeed}" class="button" onclick="return confirm(succeed_confirm)" />
					{$lang.notice_succeed}
					<br />
					<input type="submit" name="fail" value="{$lang.button_fail}" class="button" onclick="return confirm(fail_confirm)" />
					{$lang.notice_fail} {elseif $dkpt.status eq 3}
					<input type="submit" name="mail" value="{$lang.button_mail}" class="button" onclick="return confirm('{$lang.notice_mail}')" />
					{/if}
				</td>
			</tr>
		</table>
	</div>
</form>
<script language="JavaScript">{literal}

/**
 * 搜索商品
 */
function searchUsers() {
	var filter = new Object;
	filter.keyword = document.forms['searchForm'].elements['keyword'].value;

	$.get('dkpt.php?is_ajax=1&act=search_users', {
		keyword: $("#keyword").val(),
		suppliers_id: 0
	}, searchUsersResponse, 'text');
}

function searchUsersResponse(result) {

	result = $.parseJSON(result);

	if (result.error == '1' && result.message != '') {
		alert(result.message);
		return;
	}

	var sel = document.forms['theForm'].elements['user_id'];

	sel.length = 0;

	/* 创建 options */
	var users = result.content;
	if (users) {
		for (i = 0; i < users.length; i++) {
			var opt = document.createElement("OPTION");
			opt.value = users[i].user_id;
			opt.text = users[i].user_name;
			sel.options.add(opt);
		}
	} else {
		var opt = document.createElement("OPTION");
		opt.value = 0;
		opt.text = search_is_null;
		sel.options.add(opt);
	}

	return;
}



var pt_title = $("#pt_title").val();
function check_pt_title(success, error) {

	$("#pt_title-error").remove();
	$("#pt_title-success").remove();

	var value = $("#pt_title").val();
	if (value.length > 0 && pt_title != value) {

		pt_title = value;

		var url = "dkpt.php?is_ajax=1&act=check_pt_title="+pt_title;
		url = "dkpt.php?is_ajax=1&XDEBUG_SESSION_START=ECLIPSE_DBGP&act=check_pt_title&pt_title=" + pt_title;

		$.get(url, {}, function(data) {
			if (data != null && data.length > 0) {
				data = $.parseJSON(data);
				var exist = data.content;

				if (exist) {
					setError($("#pt_title"), "平台名已存在");
					pt_title_enable = false;
					if ($.isFunction(error)) {
						error();
					}
				} else {
					setSuccess($("#pt_title"), "可以使用");
					pt_title_enable = true;
					if ($.isFunction(success)) {
						success();
					}
				}
			}
		}, "text");

	} else if (value.length == 0) {
		setError($("#pt_title"), "必须填写");
	} else if (!pt_title_enable) {
		setError($("#pt_title"), "平台名已存在");
	} else if (pt_title_enable) {
		setSuccess($("#pt_title"), "可以使用");
	}
}

function setError(target, message) {
	$("#" + target.attr("id") + "-error").remove();
	$("#" + target.attr("id") + "-success").remove();
	$("#pt_title-success").remove();
	$(target).after("<label id='pt_title-error' class='error' for='pt_title'>" + message + "</label>");
	$(target).focus();
}
function setSuccess(target, message) {
	$("#" + target.attr("id") + "-error").remove();
	$("#" + target.attr("id") + "-success").remove();
	$(target).after("<label id='pt_title-success' class='success' for='pt_title'>" + message + "</label>");
}

$().ready(function() {

	var validator = $("#form1").validate();
	
	$("#btn_submit").click(function() {
		if(!validator.form()){
	        return;
	    }
		if (pt_title_enable) {
			$("#form1").submit();
		} else {
			if ($("#pt_title").val().length == 0) {
				setError($("#pt_title"), "必须填写")
			} else {
				setError($("#pt_title"), "平台名已存在")
			}
		}
		return false;
	});

	$.validator.messages["pnumber"] = "请输入大于或等于0的有效数字";

	if ("{$dkpt.id}".length == 0) {
		$("#form1").validate({
			rules: {
				msg_content: {
					required: true,
					equalTo: '#pt_url'
				}
			},
			messages: {
				msg_content: {
					equalTo: "两次输入的密码不相同！"
				}
			}
		});
	}

	$("#pt_title").blur(function() {
		check_pt_title();
	});

	$("#pt_title").keyup(function() {
		var value = $(this).val();
		if (value.length == 0 || value != pt_title) {
			// alert(value + "-"+ pt_title)
			$("#pt_title-success").remove();
		}
	});

	$("#cus_type_{$dkpt.cus_type}").attr("checked", "checked");
	$("#cus_enable_{$dkpt.cus_enable}").attr("checked", "checked");
});

//-->
{/literal}
</script>
{include file="pagefooter.htm"}
